﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ETypeInfoForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.BasicDataManage.ETypeInfoForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>添加、编辑异常原因</title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" method="post">
    <div style="padding-left: 11px; padding-bottom: 5px;">
        <table style="table-layout: fixed;">
            <tr>
                <td style="width: 120px;" align="right">
                    异常类别编码：
                </td>
                <td style="width: 300px;">
                    <input name="ETypeCode" emptytext="请输入异常类别编码" onvaluechanged="onETypeCodeChanged"
                        style="width: 300px;" class="mini-textbox" required="true" />
                </td>
            </tr>
            <tr>
                <td style="width: 120px;" align="right">
                    异常类别名称：
                </td>
                <td style="width: 300px;">
                    <input name="ETypeName" emptytext="请输入异常类别名称" style="width: 300px;" class="mini-textbox"
                        required="true" />
                </td>
            </tr>
            <tr>
                <td style="width: 120px;" align="right">
                    描述：
                </td>
                <td style="width: 300px;">
                    <input name="ETypeDesc" class="mini-textarea" style="width: 300px; height: 100px;" />
                </td>
            </tr>
        </table>
    </div>
    <div style="text-align: center; padding: 10px;">
        <a class="mini-button" iconcls="icon-save" onclick="onOk" style="width: 60px; margin-right: 20px;">
            保存</a> <a class="mini-button" iconcls="icon-cancel" onclick="onCancel" style="width: 60px;">
                取消</a>
    </div>
    <script type="text/javascript">
        mini.parse();
        var form = new mini.Form("form1");
        var action;
        function onETypeCodeChanged(e) {
            if (e.value) {
                $.ajax({
                    url: "../service/PublicHandler.ashx?action=CheckedCode&tableName=UT_EType&fieldName=ETypeCode&Code=" + e.value,
                    success: function (text) {
                        if (text > 0) {
                            mini.alert(e.value + "已经存在,请重新输入！");
                            mini.getbyName("ETypeCode").setValue("");
                        }
                    },
                    error: function () {
                    }
                });
            }
        }
        
        function onOk(e) {
            SaveData();
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }

        function SetData(data) {
            if (data.action == "edit") {
                var ETypeCode = mini.getbyName("ETypeCode");
                ETypeCode.setEnabled(false);
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                action = data.action;
                $.ajax({
                    url: "../service/BasicDataManageHandler.ashx?action=GetETypeInfo&ETypeCode=" + data.ETypeCode,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);
                    }
                });
            }
        }

        function SaveData() {
            var o = form.getData();
            var json = mini.encode([o]);
            form.validate();
            if (form.isValid() == false) return;
            if (action == "edit") {
                $.ajax({
                    url: "../Service/BasicDataManageHandler.ashx?action=ModifyEType",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
            else {
                $.ajax({
                    url: "../Service/BasicDataManageHandler.ashx?action=AddEType",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
    </script>
    </form>
</body>
</html>
